<?php 
define('IN_QY',true);
session_start();
require("include/common.inc.php");
//
if(!$_COOKIE['userid']){
    echo "<script type='text/javascript'>location.href='/wap/mlogin.php';</script>";
    exit;
}
//
$sqlmo = "update tbl_taocart set is_tax=1 where isorder=0 AND userid=".$_COOKIE['userid'];
mysql_query($sqlmo);

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="description" content="海淘购物车-众晒网" />
    <meta name="keywords" content="海淘购物车-众晒网" />
    <title>海淘购物车-众晒网</title>
    <link rel="stylesheet" type="text/css" href="ui/gwc/css/shopcar.css">
    <script type="text/javascript" src="ui/gwc/js/auto-size.js"></script>
    <script type="text/javascript" src="ui/gwc/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="/ui/layer/mobile/layer.js"></script>    
</head>
<body>
	<div class="fix_head" style="color: #333; background-image: url(/haigou/ui/img/haigoutop.png);no-repeat;background-size: 100%  100%;">
		<a href="javascript:window.history.go(-1)" class="back">
			<img src="ui/gwc/images/back.png">
		</a>
		<p style="color:#333;font-size:18px;">购物车</p>
		<a href="/wap" class="home">
			<img src="ui/gwc/images/home.png">
		</a>
	</div>
	<div class="sc_h"></div>
	<?  		    
	$sql = "select tbl_taocart.*, tbl_taospp.chtitle,tbl_taospp.goodstype, tbl_taospp.entitle,tbl_taospp.unit, tbl_taospp.img , tbl_taospp.origin from tbl_taocart left join tbl_taospp on tbl_taocart.goodsid = tbl_taospp.id where tbl_taocart.isorder=0 AND tbl_taocart.userid='".$_COOKIE['userid']."'  ORDER by tbl_taocart.id DESC ";
	$query=mysql_query($sql);
	if(!mysql_affected_rows()){
    echo '</br></br><img src="/haigou/ui/img/Artwork.png" style="margin-left:35%;">';
}

	while($row=mysql_fetch_array($query))
	{	
	?>
	
	<div class="lb">
		<div class="check">
			<div class="xz" onclick="mor(<?=$row['id']?>)" data="1" style="background-image:url(/haigou/ui/gwc/images/check_on.jpg)"></div>
		</div>
						<?php
						if(!$row['buyunit']){
				$sqlimg="SELECT img FROM tbl_taospp WHERE id= ".$row['goodsid'];
			$rowimg= mysql_query($sqlimg);
			$rowall=mysql_fetch_array($rowimg);
			$imgeve =explode(",", $rowall['img']);
			// print_r($imgeve);
			// $roweve=$rowall['ywyuedu'];						
							
						}else {
							
			$sqlimg="SELECT sku_pic FROM tbl_goods_sku WHERE id= ".$row['buyunit'];
			$rowimg= mysql_query($sqlimg);
			$rowall=mysql_fetch_array($rowimg);
			$imgeve =explode(",", $rowall['sku_pic']);	
							
						}

		              ?>	
		
		<img src=" <?=$imgeve[0]?>" class="spt">
		
		
		
		
		<div class="mid">
			<p class="name"><?=$row['chtitle']?></p>
			<p class="color">
		                <?php if($row['buyunit']==1){ ?>
					    购买方式:<?=$row['unit']?>
						<?php } ?>
						<!-- v2 -->
						<?php if($row['buyunit']==2){ ?>
						
						<?php if($row['entitle']==8){ ?>
						购买方式:张
						<?php } ?>	
											
						<?php if($row['entitle']!=8){ ?>
						购买方式:箱
						<?php } ?>						
						
						<?php } ?>	
			
			</p>
				<?php if($row['goodstype']!=3){ ?>	
			<div class="jj">
				<span class="jia" onclick="minc(<?=$row['id']?>)">-</span>
				<input class="num" value="<?=$row['goodsnum']?>">
				<span class="jian" onclick="add(<?=$row['id']?>)" >+</span>
			</div>
				<?php } ?>
				
				<?php if($row['goodstype']==3){ ?>	
			<div class="jj">

				<input class="num" value="<?=$row['goodsnum']?>" readonly="readonly">

			</div>
				<?php } ?>				
		</div>
		<div class="jgq">
			<div class="price"><p>￥<span class="pri"><?=$row['goodspri']?></span></p></div>
			
			
			 <?php if($row['vip_price']!=0.00){ ?>
			<div class="price"><p><span class="prii" style="color: #F8BC00;">￥<?=$row['vip_price']?></span><img src="/haigou/ui/img/组 25.png" style="width: 40px;"></p></div>
			
			 <?php } ?>	
			 
			<div class="price_de"><p><span><?=$row['origin']?></span></p></div>
			<img src="ui/gwc/images/del.jpg" class="del" onclick="dell(<?=$row['id']?>)" >
		</div>
	</div>

	   <?php } ?>    
	<br>
	<div class="fix_bottom">
		<div id="qx" data="1" style="background-image:url(/haigou/ui/gwc/images/check_on.jpg)"></div><span style="float:left;line-height:0.8rem;">全选</span>
		<div class="zjq">
		<p class="p1">合计:￥
		<span id="zj" >0</span>
		</p>
		<p>不含运费</p>
		</div>
		<a id="js" href="taoorder.php">结算(<span id="zsl">0</span>)</a>
	</div>
	  <?include('footer.php');?>
	<script type="text/javascript">
		$(function(){
			js();
			$(".xz").click(function(){
				var a = $(this).attr("data");
				if (a==1) {
					$(this).css("background-image","url(/haigou/ui/gwc/images/check.jpg)");
					$(this).attr("data",0)
					$("#qx").attr("data",0);
					$("#qx").css("background-image","url(/haigou/ui/gwc/images/check.jpg)");					
					
					
					
					
					

				}else{
					
						$(this).css("background-image","url(/haigou/ui/gwc/images/check_on.jpg)");
					$(this).attr("data",1)				
					

				}
				js();
			
				
			})
			$("#qx").click(function(){
				var a = $(this).attr("data");
				if (a==1) {
						$(".xz").attr("data",0);
				$(this).css("background-image","url(/haigou/ui/gwc/images/check.jpg)");
				$(".xz").css("background-image","url(/haigou/ui/gwc/images/check.jpg)");
					$(this).attr("data",0);				
			                $.ajax({
        url: './quanbuxuan.php',
        type: 'POST',
        dataType: 'json',
        data: {},
      })
	
				}else{
					
					$(".xz").attr("data",1);
				$(this).css("background-image","url(/haigou/ui/gwc/images/check_on.jpg)");
				$(".xz").css("background-image","url(/haigou/ui/gwc/images/check_on.jpg)");
				$(this).attr("data",1);
									
                $.ajax({
        url: './quanxuan.php',
        type: 'POST',
        dataType: 'json',
        data: {},
      })
				
					
				}
				js();
			})
			$(".jian").click(function (){	
						
				var a = $(this).prev().val();
				a++;
				$(this).prev().val(a);
				js();
			})
			$(".jia").click(function(){
				var a = $(this).next().val();
				a--;
				$(this).next().val(a);
				var a = $(".xz").attr("data");
				if(a==1){
					js();
				}
			})
			$(".del").click(function(){
				$(this).parent().parent().remove();
				js(); 
			})
			/*function js(){

				var num=0;
				var conut=0;

				$(".num").each(function(){

		    			var b=$(this).val()
		    		var jg=$(this).parent().parent().next().find(".pri").text();

		    		conut+=parseInt(b);
		    		num+=b*jg;
		    	
		  		});
		  		$('#zj').html(num)
			}*/
			 function js(){

				var num=0;
				var conut=0;
				$(".xz").each(function(){
					if ($(this).attr("data")==1) {
						var b = $(this).parent().next().next().find(".num").val();
						var jg = $(this).parent().next().next().next().find(".pri").text();
						conut+=parseInt(b);
		    			num+=b*jg;
					}
				})
				
		  		$('#zj').html(num);
		  		$('#zsl').html(conut);
					
			}
			
		
			
			
		})
		
  function add(a){
    var goodid = a;
    $.ajax({
        url: './addtaocart.php',
        type: 'POST',
        dataType: 'json',
        data: {goodid: goodid},
      })
      .done(function(respon) {
        if (respon.error==0) {
        
    
        }else{
     
        }
      })
  } 
  function minc(b){
    var goodid = b;
    $.ajax({
        url: './mintaocart.php',
        type: 'POST',
        dataType: 'json',
        data: {goodid: goodid},
      })
      .done(function(respon) {
        if (respon.error==0) {

      
        }else{
        
        }
      })
  }	

  function mor(d){
    var goodid = d;
    
    $.ajax({
        url: './morcart.php',
        type: 'POST',
        dataType: 'json',
        data: {goodid: goodid},
      })
      .done(function(respon) {
        if (respon.error==0) {

       
        }else{

        }
      })
	
  }	
  
  function dell(f){
    var goodid = f;
    $.ajax({
        url: './delcart.php',
        type: 'POST',
        dataType: 'json',
        data: {goodid: goodid},
      })
      .done(function(respon) {
        if (respon.error==0) {
             layer.open({
    content: '删除成功'
    ,skin: 'msg'
    ,time: 2 //2秒后自动关闭
  });
      
        }else{
            
        
        }
      })

  }	


	</script>
	
	
<script>

</script>
	
	
	
	
</body>
</html>